How it works
Currently, the integration captures client-side and server-side operations separately, but does not provide end-to-end visibility into their interaction. There’s an ongoing proposal to add OpenTelemetry trace support to MCP to enable end-to-end observability. For more information, see GitHub discussion #269.
weave.op()
decorator. Specifically, it patches methods in the mcp.server.fastmcp.FastMCP
and mcp.ClientSession
classes.
Through this integration, Weave traces the following MCP components:

Use the integration
The Weave integration works with both the MCP server and client. Once installed, you can enable tracing with just two additional lines of code—one to importweave
, and another to initialize it.
Prerequisites
Before you begin, install the required packages:Configuration
The MCP integration can be configured through environment variables:MCP_TRACE_LIST_OPERATIONS
: Set totrue
to trace list operations (list_tools
,list_resources
, andlist_prompts
) on both server and client sides.
Server-side integration
To trace an MCP server, add two lines to your existingFastMCP
setup: one to import Weave and one to initialize the client. Once added, tool, resource, and prompt operations will be automatically traced.
Client-side integration
On the client side, tracing also requires just two changes: import Weave and initialize it. All tool calls, resource accesses, and prompt requests will be traced automatically.Tutorial: mcp_demo
example
The mcp_example
demonstrates an integration between the Model Context Protocol (MCP) and Weave for tracing. It showcases how to instrument both the client and server components to capture detailed traces of their interactions.
Run the example
-
Clone the
weave
repository and navigate to themcp_demo
example:The example includes two main files:example_server.py
: A demo MCP server built withFastMCP
. It defines tools, resources, and prompts.example_client.py
: A client that connects to the server and interacts with its components.
-
Install the required dependencies manually:
-
Run the demo:
This command launches both the client and server. The client starts an interactive CLI where you can test various features.
Client CLI commands
The client interface supports the following commands:Command | Description |
---|---|
tools | List available tools |
resources | List available resources |
prompts | List available prompts |
add <a> <b> | Add two numbers |
bmi <weight> <height> | Calculate Body Mass Index |
weather <city> | Get weather data for a city |
greeting <name> | Get a personalized greeting |
user <id> | Retrieve a user profile |
config | Fetch app configuration |
code-review <code> | Generate a code review prompt |
debug <error> | Generate a debugging prompt |
demo | Run a full demo of all available features. This will run each feature in sequence and produce a full trace timeline of interactions in the Weave UI. |
q | Quit the session |
Understanding the example
Theexample_server.py
server defines the following:
- Tools: Functions such as
add()
,calculate_bmi()
,fetch_weather()
- Resources: Endpoints like
greeting://{name}
,config://app
,users://{id}/profile
- Prompts: Templates like
review_code()
anddebug_error()
weave.init()
.
The example_client.py
client demonstrates how to:
- Connect to an MCP server
- Discover available tools, resources, and prompts
- Call tools with parameters
- Read from resource URIs
- Generate prompts with arguments
- Show usage of
weave.op()
with custom methods/functions.
FAQ
Why is MCP tracing needed?
As an LLM application developer, you fall into one of three categories:- MCP server-side developer: You want to expose multiple tools, resources, and prompts to the MCP client. You expose your existing application’s tools, resources, etc., or you have built agents or have multiple agents orchestrated by an orchestrator agent.
- MCP client-side developer: You want to plug your client-side application into multiple MCP servers. A core part of your client-side logic is making LLM calls to decide which tool to call or which resource to fetch.
- MCP server and client developer: You are developing both the server and the client.
- Quickly iterate through your application
- Audit the workflow or execution logic
- Identify bottlenecks